<?php


namespace app\common\service\store;


use app\admin\model\store\GoodsCate;
use app\common\service\BaseService;
use think\facade\Cache;

class GoodsCateService extends BaseService
{
    /**
     * Author:Yingbo Sun
     * 分类接口
     * @return array
     * @throws \Psr\SimpleCache\InvalidArgumentException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function goodCates()
    {
        $redis = Cache::store('redis');
        $redis->select(11);
        $bool = $redis->has("goodsCateList");
        if ($bool){
            $arr = $redis->get("goodsCateList");
        }else{
            $data = GoodsCate::select();
            $data && $data = $data->toArray();
            $arr = getSon($data);
            if (empty($arr)){
                $redis->set("goodsCateList",$arr,300);
            }
            $redis->set("goodsCateList",$arr);
        }

        return self::success('成功', $arr);
    }

    public static function fatherCate()
    {
        $data = GoodsCate::where('pid', 0)->select();
        $data && $data = $data->toArray();
        return self::success('成功', $data);
    }
}